const path = require('node:path')
const express = require('express')

const root = process.cwd()

// https://www.expressjs.com.cn/
const app = express()

app.use((req, res, next) => {
    // console.log(
    //     new Date().toLocaleString(),
    //     '\n',
    //     !!req.headers
    // )
    next()
})

app.use(express.static(path.resolve(root, 'dist')))
app.use(express.static(path.resolve(root, 'demo')))

function start() {
    const PORT = 3030
    const HOST = '127.0.0.1'
    app.listen(PORT, err => {
        if (err) {
            console.error('start error', err?.message)
            throw err;
        }
        console.log(`start http://${HOST}:${PORT}`)
    })
}

start()
